package com.vastcom.bmi.action;

import org.springframework.web.bind.annotation.*;
import to.Parm;
import vo.Result;
@CrossOrigin
@RestController
public class PublicAction {

    @GetMapping("hello")
    @ResponseBody
    public  String helloWord() throws Exception{
        return "hello word springboot";
    }




    @PostMapping("bmivalue")
    @ResponseBody
    public Result bmivalue(@RequestBody Parm parm) throws Exception{
        float sgf=Float.parseFloat(parm.getSg());
        float tzf=Float.parseFloat(parm.getTz());
        float result=tzf/(sgf*sgf);

        String suggest="";
        if (result<=18.4){
            suggest="thin";
        }
        else if (result>18.5&&result<=23.9)
        {
            suggest="normal";
        }
        else if (result>23.9&&result<=27.9)
        {
            suggest="overwight";
        }
        else
        {
            suggest="fat";
        }

        Result r=new Result();
        r.setSg(parm.getSg());
        r.setTz(parm.getTz());
        r.setResult(result);
        r.setSuggest(suggest);


        return r;
    }
}
